<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class Carts extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        $sku = $this->product;
        $product = $sku->product;
        return [
            'id' => $this->id,
            'cover' => Images::make($sku->cover ?: $product->cover),
            'name' => $product->name,
            'description' => $sku->description,
            'stock' => $sku->stock,
            'price' => $sku->price,
            'number' => $this->number,
            'coupon' => Coupons::collection($product->coupons),
        ];
    }
}
